<template>
  <div class="page_container">
    <PageTitle />

    <ScrollContainer>
      <Form
        :data="opts"
        :rows="4"
        :cols="2"
        label-width="85px"
        readonly
      />

      <template #btns>
        <el-button @click="back" round>
          返回
        </el-button>
      </template>
    </ScrollContainer>
  </div>
</template>

<script>
import {
  getContributionDetail,
} from '@/api/home/contribution.js';
import { changeForm } from '@u/form.js';

export default {
  name: 'ContributionDetail',
  data() {
    return {
      id: this.$route.params.id,
      opts: {
        accountId: {
          label: '会员名称：',
          belong: 'accountObj.name',
          value: '',
          position: [1, 1],
        },
        goods: {
          label: '物品：',
          value: '',
          position: [2, 1],
        },
        money: {
          label: '货币：',
          value: '',
          position: [],
        },
        integral: {
          label: '积分：',
          value: '',
          position: [3, 1],
        },
        activityId: {
          label: '贡献来源：',
          value: '',
          position: [4, 1],
        },
        type: {
          label: '贡献类型：',
          belong: 'activityObj.name',
          value: '',
          position: [1, 2],
        },
        estimated: {
          label: '物品预估价值：',
          value: '',
          labelWidth: '115px',
          position: [2, 2],
        },
        time: {
          label: '贡献时间：',
          value: '',
          position: [3, 2],
        },
        mode: {
          label: '贡献方式：',
          belong: 'modeObj.name',
          value: '',
          position: [4, 2],
        },
      },
    };
  },
  created() {
    getContributionDetail(this.id).then(res => {
      if (res.code == 200) {
        // console.log(res.data);
        this.changeType(res.data.typeObj.id);
        changeForm(this.opts, res.data, true);
      }
    });
  },
  methods: {
    changeType(typeId) {
      const obj = {
        goods: [[2, 1], []],
        money: [[], [2, 1]],
        estimated: [[2, 2], []],
        integral: [[3, 1], [2, 2]],
        activityId: [[4, 1], [3, 2]],
        time: [[3, 2], [3, 1]],
        mode: [[4, 2], [4, 1]],
      };
      for (const k in obj) {
        switch (typeId) {
          case 1:
            this.opts[k].position = obj[k][0];
            break;
          case 2:
            this.opts[k].position = obj[k][1];
            break;
        }
      }
    },
    back() {
      this.navigateBack({
        to: {
          name: 'Contribution',
        },
        from: this.$route.params.from,
        params: {
          removeTagViews: ['ContributionDetail']
        }
      });
    }
  },
  components: {
    Form: () => import('@c/Form.vue')
  }
};
</script>

<style lang="scss" scoped>

</style>
